<template>
  <div class="">
    <canvas id="c"></canvas>
  </div>
</template>

<script>
/**
 *  @description
 *  @author
 *
 */
import { StaticCanvas, FabricText } from 'fabric';
export default {
  components: {

  },
  data() {
    return {
      canvas: null,
      fabricText: null,
    }
  },
  computed: {

  },
  created() {

  },
  mounted() {
  },
  methods: {
    initFabric() {
      this.canvas = new StaticCanvas();
      this.fabricText = new FabricText('Hello World');
      this.canvas.add(this.fabricText);
      this.canvas.centerObject(this.fabricText);
      const imageSrc = this.canvas.toDataURL();
      // 下面是下载的代码
      const a = document.createElement('a');
      a.href = imageSrc;
      a.download = 'image.png';
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
    }
  },
  watch: {

  },
}
</script>

<style scoped></style>